#include "stdafx.h"
#include "traytest.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


CComModule _Module;

CTrayApp theApp;


BEGIN_MESSAGE_MAP(CTrayApp, CWinApp)
	//{{AFX_MSG_MAP(CTrayApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

CTrayApp::CTrayApp() : m_pCurrentAboutDlg(NULL)
{
}

BOOL CTrayApp::InitInstance()
{
  //Initialize ATL
  _Module.Init(NULL, m_hInstance);

  CMainFrame* pMainFrame = new CMainFrame;
  m_pMainWnd = pMainFrame;
  if (!pMainFrame->Create(NULL, _T("Traytest")))
    return FALSE;

  m_pMainWnd->ShowWindow(SW_HIDE);
  m_pMainWnd->UpdateWindow();

	return TRUE;
}

int CTrayApp::ExitInstance()
{
  //Terminate ATL
  _Module.Term();

  return CWinApp::ExitInstance();
}

void CTrayApp::OnAppAbout()
{
  //avoid bringing up two versions of the dialog
  if (m_pCurrentAboutDlg)
  {
    m_pCurrentAboutDlg->SetForegroundWindow();
    return;
  }

  //Show the window
	CDialog aboutdlg(IDD_ABOUTBOX);
  m_pCurrentAboutDlg = &aboutdlg;
  aboutdlg.DoModal();
  m_pCurrentAboutDlg = NULL;
}

